define(function(require, exports, module) {
    "use strict";
    var $ = require("$"),
        app = require("dist/application/app"),
        config = app.config;
    var $dragClassify = $("#dragClassify"),
        $noClassify = $("#noClassify"),
        $save_class = $("#save_class"),
        $nestableMenu = $("#nestableMenu");
    $dragClassify.length > 0 && require.async("nestable", function() {
        $dragClassify.nestable({
            maxDepth: 2
        });
        $('.dd-handle a').on('mousedown', function(e) {
            e.stopPropagation();
        });

    })
    $save_class.on('click', function() {
        var $this = $(this),
            $remote = $this.data('remote') || $this.attr('href');
        $this.button('loading');
        var data = (window.JSON.stringify($dragClassify.nestable('serialize')))
        $.post($remote, {data:data}).done(function(d) {
            $this.button('reset')
            if (config.issucceed(d)) {
                config.msg.suc(d.message || config.lang.saveSuccess, d.url)
            } else {
                config.msg.error(d.message || config.lang.saveError, d.url)
            }
        }).fail(function() {
            $this.button('reset')
            config.msg.info(config.lang.exception, d.url)
        });
    });
    $nestableMenu.on('click', function() {
        var $expand = $(this).hasClass('active')
        $dragClassify.nestable($expand ? 'expandAll' : 'collapseAll');
    });
  
})
